package com.effect.exception;

import lombok.Getter;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 自定义异常信息
 */
@Getter
public class BizException extends RuntimeException {
    /**
     * 响应是否成功
     */
    private Boolean success;
    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String message;

    private String errorLevel;

    private String errorMdg;

    private String debugMsg;

    private List<String> traceList;

    private transient Object[] messageFormatArgs;
    private transient Object data;

    public static final List<String> ERROR_PRODUCED_BY_CURRENT_SYSTEM_TRACE_ID = Collections.singletonList("5");

    private static final String CURRENT_SYSTEM_TRACE_ID = "5";


    public BizException(String message) {
        // this.messageFormatArgs = messageFormatArgs;
        this.message = message;
        this.success = false;
        this.code = 400;
        this.data = data;
        if (traceList == null) {
            this.traceList = ERROR_PRODUCED_BY_CURRENT_SYSTEM_TRACE_ID;
        } else {
            this.traceList = new ArrayList<>(traceList);
            this.traceList.add(CURRENT_SYSTEM_TRACE_ID);
        }
    }



     public BizException(ResultCode message, Object... messageFormatArgs) {
        super(MessageFormat.format(message.getValue(), messageFormatArgs));
        this.message = MessageFormat.format(message.getValue(), messageFormatArgs);
        this.messageFormatArgs = messageFormatArgs;
        this.success = false;
        this.code = message.getCode();
    }





}
